package com.huahai.util;

import com.huahai.exception.BusinessException;
import com.huahai.exception.ErrorCode;

/**
 * 自定义异常抛出工具类
 * @author huahai
 */
public class ThrowUtils {

    /**
     * 条件判断，满足条件则抛出异常
     * @param condition
     * @param runtimeException
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 条件判断，满足条件则抛出异常
     * @param condition
     * @param errorCode
     */
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    /**
     * 条件判断，满足条件则抛出异常
     * @param condition
     * @param errorCode
     */
    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }


}
